package activemq.queue1;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/*
 * 2019/1/13 15:05
 * by activemq
 */
public class Producer {
    public static void main(String[] args) throws JMSException, InterruptedException {
        System.out.println("producer start");
        ConnectionFactory factor=new ActiveMQConnectionFactory(
                ActiveMQConnectionFactory.DEFAULT_USER,
                ActiveMQConnectionFactory.DEFAULT_PASSWORD,
                "tcp://localhost:61616");
                //"failover:(tcp://192.168.0.102:61616,tcp://192.168.0.102:61617,tcp://192.168.0.102:61618)?Randomize=false");
        Connection connection = factor.createConnection();
        connection.start();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        //Session session = connection.createSession(true,Session.AUTO_ACKNOWLEDGE);

        Destination destination = session.createQueue("queue1");
        MessageProducer producer = session.createProducer(destination);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        for(int i=0;i<500;i++)
        {
            TextMessage text = session.createTextMessage();
            text.setText("消息内容"+i);
            producer.send(text);
            //session.commit();
            Thread.sleep(1000);
        }
        connection.close();
    }
}